<?php
class Bootstrap
{
	private static $_currAppPath;
	
	public static function run()
	{
		require_once 'V/URI.php';
		require_once 'V/Router.php';
		require_once 'V/Controller.php';
		$URI = new V_URI();
		$RTR = new V_Router();
		$conFile = VPATH_MYAPP.DS.'controllers'.DS.$RTR->fetchDirectory().$RTR->fetchClass().'.php';
		if ( ! file_exists($conFile))
		{
			die('Unable to load your controller file. "'.$conFile.'"');
		}

		include($conFile);
		
		$class  = $RTR->fetchClass();
		$method = $RTR->fetchMethod();

		if ( ! class_exists($class)	
			OR $method == 'controller'	
			OR strncmp($method, '_', 1) == 0
			OR in_array(strtolower($method), array_map('strtolower', get_class_methods('V_Controller')))
			)
		{
			die("{$class}/{$method}");
		}
		
		$V = new $class();
		// Call the requested method.
		// Any URI segments present (besides the class/function) will be passed to the method for convenience
		call_user_func_array(array(&$V, $method), array_slice($URI->getRsegments(), 2));
	}
}







